
#include "IMenuItem.h"
#include "member_BWidget.h"

using namespace BWE;

void IMenuItem::dispenseStyles(const BStyle* style)
{
	if (action)
	{
		BIcon* icon = 0;
		if (action->name().size())
			icon = style->icon(action->name());
		if (!icon)
			icon = style->icon(action->text());
		if (icon)
			action->setIcon(icon);
	}
	else if (menu)
	{
		if (widget_member(menu)->dirtyStyle)
			menu->flush();
		BIcon* icon = 0;
		if (menu->name().size())
			icon = style->icon(menu->name());
		if (!icon)
			icon = style->icon(menu->title());
		if (icon)
			menu->setIcon(icon);
	}
	color.reset();
	graph = Graph_None;
	image = 0;
	icon = 0;
	text.clear();
	if (action)
	{
		color = action->color();
		graph = action->graph();
		image = action->image();
		icon = action->icon();
		text = action->text();
	}
	if (menu)
	{
		icon = menu->icon();
		text = menu->title();
	}
	IAlignItem::dispenseStyles(style);
}
void IMenuItem::translateText(const BStyle* style)
{
	if (menu)
	{
		block.text = widget_member(menu)->t_title;
	}
}

void IMenuItem::freshSize(const BFont* font, int width)
{
	IAlignItem::freshSize(font, width);
	expandSize.reset();
	expandArea.reset();
	shortcutRect.reset();
	shortcutSize.reset();
}
void IMenuItem::freshRects()
{
	IAlignItem::freshRects();
	if (expandSize.valid() && shortcutSize.valid())
	{
		expandArea = rectCenter.align(Align_RightCenter, expandSize);
		shortcutRect = expandArea.align(Align_LeftCenter, shortcutSize);
	}
}



